﻿using ProtoBuf.Message;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace AutoChess
{
  
    /*class GridUnitEx
    {
        /// <summary>格子所属的地图 </summary>
        public AutoChessMapMgr AutoChessMapMgr;

        /// <summary>格子停留的英雄 (注意移除、设置) </summary>
        public ACHero heroUnit;

        /// <summary> 格子的渲染器 </summary>
        public GridUnitRenderer gridUnitRender;

        private int Row, Column;
        private int localIndex;
        private GridType gridType;
        private Vector3 size;
        private Vector3 position;
        private Vector3 boxOffset;
        private bool canEnter = true;

        private bool isSelect = false;
        public int RowIndex
        {
            get { return Row; }
        }
        public int ColumnIndex
        {
            get { return Column; }
        }
        public bool IsSelect
        {
            get {  return isSelect; }
            set { isSelect = value; }
        }
        public GridType GridType
        {
            get { return gridType; }
            set { gridType = value; }
        }
        public int LocalIndex
        {
            get { return localIndex; }
            set { localIndex = value; }
        }
        public int ServerIndex
        {
            get { return (int)gridType *100 + localIndex + 1; }
        }
        public int EnemyServerIndex
        {
            get { return (int)GridType.FightGrid*100 + localIndex + 1; }
        }
        /// <summary>格子世界坐标 </summary>
        public Vector3 Position
        {
            get { return position; }
            set { position = value;}
        }

        public Vector3 Size
        {
            get { return size; }
            set { size = value; }
        }
        public Vector3 BoxOffset
        {
            get { return boxOffset; }
            set { boxOffset = value; }
        }
        public bool CanEnter
        {
            get { return canEnter; }
        }

        public GridUnit(AutoChessMapMgr autoChessMapMgr, int row, int column, GridType gridType)
        {
            this.AutoChessMapMgr = autoChessMapMgr;
            this.Row = row;
            this.Column = column;
            this.gridType = gridType;
        }

        /// <summary>
        /// 有英雄单位进入
        /// </summary>
        /// <param name="heroUnit"></param>
        public void OnEnter(ACHero heroUnit)
        {
            this.heroUnit = heroUnit;
        }

        /// <summary>
        /// 英雄单位离开的时候
        /// </summary>
        public void OnLeave()
        {
            this.heroUnit = null;
        }


        public  void OnDestroy()
        {
            canEnter = true;
            size = new Vector3(1, 0.1f, 1);
            position = Vector3.zero;
            AutoChessMapMgr = null;
            heroUnit = null;
        }
        /// <summary>
        /// 添加一个格子渲染器
        /// </summary>
        /// <param name="renderer"></param>
        public  void ConnectRenderer(BaseRenderer renderer)
        {
            var temp = renderer as GridUnitRenderer;
            if (temp == null)
            {
                Debug.LogError("Grid Unit connect renderer failed . Renderer nail !");
                return;
            }

            if (gridUnitRender != null)
                DisconnectRenderer();

            gridUnitRender = temp;
            gridUnitRender.OnConnect(this); 
        }
        public  void DisconnectRenderer()
        {
            if (gridUnitRender != null)
            {
                gridUnitRender.OnDisconnect();
                gridUnitRender = null;
            }
        }

        /// <summary>
        /// 刷新格子渲染器状态
        /// </summary>
        public void RefreshRenderer()
        {
            if(gridUnitRender != null)
            {
                gridUnitRender.RefreshRenderer();
            }
        }

        #endregion

        public bool EqualsGrid(int cliendIndex , GridType type)
        {
            return cliendIndex == localIndex && type == gridType;
        }

        public override string ToString()
        {
            return string.Format("[{0}-{1},{2}]\n",gridType.ToString(),Row,Column);
        }

 
       
    }*/
}